<?php
/**
 * Sistema de gerenciamento de empresas da construção cívil em jQuery. O PHP é usado apenas como template das páginas
 * funcionando da seguinte forma:
 * 
 * index.php?go=<nomeDaPagina>
 * 
 * nomeDaPagina será carregado como um arquivo PHP na DIV "pagina".
 * js/nomeDaPagna.js será carregado após o jquery carregar
 * 
 * Todo acesso a dados é feito pelo PHP. Cada arquivo PHP possui a parte
 * HTMl e a parte JavaScript no mesmo arquivo, para facilitar
 * 
 */
session_start();
if (isset($_GET["go"])) {
    if (!file_exists($_GET["go"] . ".html"))
        $_GET["go"] = "login";
}
else {
    $_GET["go"] = "login";
}
?>
<!DOCTYPE html>
<html>
    <head>
        <title>MK Builder</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!--        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
                <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet"/>-->
        <link href="cssJquery/jquey-ui.css" rel="stylesheet"/>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
        <!-- Optional theme -->
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">


        <!--<link href="css/base/jquery-ui.css" rel="stylesheet"/>-->
        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
          <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon"/>
        <style type="text/css">
            body {
                margin-bottom: 120px;
            }

            .btn.dropdown-toggle ~ .dropdown-menu, 
            ul.nav li.dropdown ul.dropdown-menu {
                background-color: rgb(244, 244, 244);
                background-color: rgb(255, 255, 255);
                border: 0 solid rgb(66, 133, 244);
                box-shadow: 0px 0px 3px rgba(25, 25, 25, 0.3);
                top: 0px;
                margin: 0px;
                padding: 0px;
            }
            ul.nav li.dropdown ul.dropdown-menu {
                position: absolute;
                width: 100%;
            }
            .dropdown-menu .dropdown-plus-title {
                width: 100%;
                color: rgb(51, 51, 51);
                padding: 6px 12px;
                font-weight: 800;
                border: 0 solid rgb(173, 173, 173);
                border-bottom-width: 2px;
                cursor: pointer;
            }

            ul.nav li.dropdown ul.dropdown-menu .dropdown-plus-title {
                padding-top: 10px;
                padding-bottom: 10px;
                line-height: 20px;
            }

            .btn.dropdown-toggle.btn-primary ~ .dropdown-menu .dropdown-plus-title {
                border-color: rgb(53, 126, 189);
            }
            .btn.dropdown-toggle.btn-success ~ .dropdown-menu .dropdown-plus-title {
                border-color: rgb(76, 174, 76);
            }
            .btn.dropdown-toggle.btn-info ~ .dropdown-menu .dropdown-plus-title {
                border-color: rgb(70, 184, 218);
            }
            .btn.dropdown-toggle.btn-warning ~ .dropdown-menu .dropdown-plus-title {
                border-color: rgb(238, 162, 54);
            }
            .btn.dropdown-toggle.btn-danger ~ .dropdown-menu .dropdown-plus-title {
                border-color: rgb(212, 63, 58);
            }

            @media (min-width: 768px) {
                ul.nav li.dropdown ul.dropdown-menu .dropdown-plus-title {
                    padding-top: 15px;
                    padding-bottom: 15px;
                }
            }
            @media (min-width: 768px) {
                ul.nav li.dropdown ul.dropdown-menu {
                    width: auto;
                }
            }
        </style>
    </head>
    <body>

        <div class="container">
            <div class="row">    
                <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
                    <div class="container-fluid">
                        <!-- Brand and toggle get grouped for better mobile display -->
                        <div class="navbar-header">
                            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                                <span class="sr-only">Toggle navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>
                            <a class="navbar-brand" href="https://www.mescker.com" target="_blank">MK Builder</a>
                        </div>
                        <!-- Collect the nav links, forms, and other content for toggling -->
                        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                            <ul class="nav navbar-nav">
                                <?php

                                /**
                                 * Menu é montado de acordo com a pessoa logada (sessão)
                                 */
                                function getActive($go) {
                                    if ($go == $_GET["go"])
                                        return "class='active'";
                                    return '';
                                }

                                $mensagemUsuario = "";
                                $usuario         = null;

                                //Obtém o cookie da pessoa logada
                                if (isset($_COOKIE['usuario'])) {
                                    $usuario         = json_decode($_COOKIE['usuario']);
                                    $mensagemUsuario = "Olá {$usuario->nome} [ <a id='linkPerfil' href='index.php?go=perfil' class='navbar-link'>Perfil</a> - <a id='linkSair' href='#' class='navbar-link'>Sair</a> ] ";

                                    if (!isset($_SESSION["login_id"])) {
                                        $_SESSION["login_id"]   = $usuario->id;
                                        $_SESSION["login_tipo"] = $usuario->tipo;
                                    }
                                }

                                if (isset($usuario)) {
                                    if ($usuario->tipo == "a") {

                                        echo'<li><a href = "index.php?go=bemVindo">Home</a></li>';

                                        echo'<li>';
                                        echo'<a href = "#" class = "dropdown-toggle" data-toggle = "dropdown">Empreendimentos<b class = "caret"></b></a>';
                                        echo'<ul class = "dropdown-menu">';
                                        echo'<li class = "dropdown-plus-title">';
                                        echo'Ações';
                                        echo'<b class = "pull-right glyphicon glyphicon-chevron-up"></b>';
                                        echo'</li>';
                                        echo'<li><a href = "index.php?go=empreendimento">Gerenciar Empreendimentos</a></li>';
                                        echo'<li><a href = "#">Gerenciar Aptos</a></li>';
                                        echo'</ul>';
                                        echo'</li>';

                                        echo'<li>';
                                        echo'<a href = "#" class = "dropdown-toggle" data-toggle = "dropdown">Financeiro <b class = "caret"></b></a>';
                                        echo'<ul class = "dropdown-menu">';
                                        echo'<li class = "dropdown-plus-title">';
                                        echo'Ações';
                                        echo'<b class = "pull-right glyphicon glyphicon-chevron-up"></b>';
                                        echo'</li>';
                                        echo'<li><a href = "#">Contas a Pagar e Receber</a></li>';
                                        echo'<li><a href = "#">Controle de Cheques</a></li>';
                                        echo'<li><a href = "#">Lançamento de Notas</a></li>';
                                        echo'<li><a href = "#">Fluxo de Caixa</a></li>';
                                        echo'</ul>';
                                        echo'</li>';

                                        echo'<li>';
                                        echo'<a href = "#" class = "dropdown-toggle" data-toggle = "dropdown">Aplicativo <b class = "caret"></b></a>';
                                        echo'<ul class = "dropdown-menu">';
                                        echo'<li class = "dropdown-plus-title">';
                                        echo'Ações';
                                        echo'<b class = "pull-right glyphicon glyphicon-chevron-up"></b>';
                                        echo'</li>';
                                        echo'<li><a href = "index.php?go=usuarioApp">Gerenciar Usúarios</a></li>';
                                         echo'</li>';
                                        echo'</ul>';
                                    }

//                                if ($usuario->tipo == "v") {  
//                                    echo "<li " . getActive('bemVindo') . "><a href = 'index.php?go=bemVindo'>Home</a></li>";
//                                    echo "<li " . getActive('clientes') . "><a href = 'index.php?go=clientes'>Clientes</a></li>";
//                                    echo "<li " . getActive('produtos') . "><a href = 'index.php?go=produtos'>Produtos</a></li>";
//                                    echo "<li " . getActive('pdv') . "><a href = 'index.php?go=pdv'>PDV</a></li>";
//                                }
                                }
                                ?>
                            </ul> 
                            <p class="navbar-text pull-right"><?php echo $mensagemUsuario ?></p>
                        </div><!-- /.nav-collapse -->
                    </div>
                </nav>
            </div><!-- /navbar-inner -->
        </div>
        <div class="container" style="padding-top: 60px;" id="conteudo">
            <?php require($_GET["go"] . ".html") ?>
        </div> <!-- /container -->

        <div class="container">
            <div class="row">    
                <nav class="navbar navbar-default navbar-fixed-bottom" role="navigation">
                    <div class="container-fluid">
                        <a target="_blank" href="http://www.mescker.com"><img class="pull-right" src="img/mklogo_h60.png" id="mklogo"/></a>
                        <br/>
                        <center>Copyright © <?php echo date('Y') ?> | <a target="_blank" href="http://www.mescker.com"> Mescker Tecnologia Sistemas e Web Sites</a> Todos Direitos Reservados.</center>
                    </div>
            </div>
        </div>
<!--        <script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>-->
        <script src="js/libs/jquery.js" type="text/javascript"></script>
        <script src="js/libs/jquery-ui-1.10.0.custom.min.js" type="text/javascript"></script>
        <script src="js/libs/jquery.maskMoney.js" type="text/javascript"></script>
        <script src="js/libs/jquery.cookie.js" type="text/javascript"></script>
        <script src="js/app.js" type="text/javascript"></script>
        <!-- Latest compiled and minified JavaScript -->
        <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
        <!-- toda página tem o seu arquivo JS relativo -->
        <script src="<?php echo 'js/' . $_GET["go"] . ".js"
            ?>" type="text/javascript"></script>
    </body>
</html>